import {resetForm} from 'plugins/utils.js'

export function loadSucess (state, payload) {
  state.fields = payload
  state.selectedHost = payload.hosts
  state.loading.hide()
}

export function reset (state) {
  state.fields = {}
  resetForm(state.msg)
}

export function saveSuccess (state) {
  state.loading.hide()
  this.$router.push('/listservice')
}

export function saveFail (state, payload) {
  state.loading.hide()
  for (var name in payload) {
    state.msg[name] = payload[name][0]
  }
}

export function envSuccess (state, payload) {
  let res = JSON.parse(payload)
  state.tableData = res.host
}

export function watchSelectedHost (state) {
  let array = []
  for (let i in state.selectedHost) {
    array[i] = state.selectedHost[i].value
  }
  state.fields.host = array
}

export function clearBoth (state) {
  state.fields.host = []
  state.selectedHost = []
}
